home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / vim2html.pl < prev    next >
Encoding:
Perl Script  |  2001-07-28  |  2.4 KB  |  117 lines

  1. #!/usr/bin/env perl
  2.  
  3. # converts vim documentation to simple html
  4. # Sirtaj Singh Kang (taj@kde.org)
  5.  
  6. # Wed Oct  8 01:15:48 EST 1997
  7.  
  8. $date = `date`;
  9. chop $date;
  10.  
  11. %url = ();
  12.  
  13. # Read the specified tag file.  For each tag, convert the filename into a
  14. # hyperlink and save it in an associative array using the tag as the index.
  15. sub readTagFile
  16. {
  17.     my($tagfile) = @_;
  18.     local( $tag, $file, $name );
  19.  
  20.     open(TAGS,"$tagfile") || die "can't read tags\n";
  21.  
  22.     while( <TAGS> ) {
  23.         s/</</g;
  24.         s/>/>/g;
  25.  
  26.         # For each line in the tag file, save the first two items
  27.         # into backreferences, the first holding the tag itself,
  28.         # and the second holding the file containing the tag.
  29.         /^(.*)\t(.*)\t/;
  30.  
  31.         $tag = $1;
  32.         ($file= $2) =~ s/.txt$/.html/g;
  33.  
  34.         $url{ $tag } = "<A HREF=\"$file#$tag\">$tag</A>";
  35.  
  36.         #print "($tag, $file, $tag)\n";
  37.     }
  38.     close( TAGS );
  39. }
  40.  
  41. # Convert the specified text file into an html file.  For each line in the
  42. # file, convert any words between asterices into page anchors, and convert
  43. # any words between bar characters into hyperlinks.
  44. sub vim2html
  45. {
  46.     my( $infile ) = @_;
  47.     local( $outfile );
  48.  
  49.     open(IN, "$infile" ) || die "Couldn't read from $infile.\n";
  50.  
  51.     # Strip off any path information from the supplied filename.
  52.     # TODO: will this work on DOS paths using a backslash?
  53.     ($outfile = $infile) =~ s%.*/%%g;
  54.     $outfile =~ s/\.txt$//g;
  55.  
  56.     open( OUT, ">$outfile.html" )
  57.             || die "Couldn't write to $outfile.html.\n";
  58.  
  59.     print OUT<<EOF;
  60. <HTML>
  61. <HEAD><TITLE>$outfile</TITLE></HEAD>
  62. <BODY BGCOLOR="#ffffff">
  63. <H1>Vim Documentation: $outfile</H1>
  64. <HR>
  65. <PRE>
  66. EOF
  67.  
  68.     while( <IN> ) {
  69.         s/</</g;
  70.         s/>/>/g;
  71.  
  72.         # Convert tags between asterices into page targets
  73.         s/\*([^*\s]*)\*/\*<A NAME="$1"><B>$1<\/B><\/A>\*/g;
  74.  
  75.         # Convert tags between bars into hyperlinks
  76.         s/\|([^|\s]*)\|/\|$url{$1}\|/g;
  77.  
  78.         print OUT $_;
  79.     }
  80.     print OUT<<EOF;
  81. </PRE>
  82. <p><i>Generated by vim2html on $date</i></p>
  83. </BODY>
  84. </HTML>
  85. EOF
  86.  
  87. }
  88.  
  89. # Display the usage information for the script.
  90. sub usage
  91. {
  92. die<<EOF;
  93. vim2html.pl: converts vim documentation to HTML.
  94. usage:
  95.  
  96.     vim2html.pl <tag file> <text files>
  97. EOF
  98. }
  99.  
  100. # Main processing
  101.  
  102. if ( scalar(@ARGV) < 2 ) {
  103.     usage();
  104. }
  105.  
  106. print "Processing tags...\n";
  107. readTagFile( $ARGV[ 0 ] );
  108.  
  109. # Individually process each file pattern supplied on the command line.
  110. foreach $file ( 1..$#ARGV ) {
  111.     # Process each pattern as if it contains wildcards.
  112.     while ($filename = <$ARGV[$file]>) {
  113.     print "Processing ".$filename."...\n";
  114.     vim2html( $filename );
  115.     }
  116. }
  117.